<template>
  <div
    :class="[
      'msg',
      data.uid === userStore.userInfo?.id ? 'my-msg' : 'other-msg'
    ]"
  >
    <!-- <img v-lazy="data.avatarUrl" alt="" /> -->
    <el-image
      style="width: 40px; height: 40px"
      :src="data.avatarUrl"
      :preview-src-list="[data.avatarUrl]"
      fit="cover"
    />
    <div class="content">
      <span class="username">{{ data.username }}</span>
      <pre class="usercontent">{{ data.content }}</pre>
    </div>
  </div>
</template>

<script setup lang="ts">
import user from "@/store/user";
const userStore = user();
// 定义组件属性
const { data } = defineProps<{
  data: {
    uid: number;
    avatarUrl: string;
    username: string;
    content: string;
  };
}>();
</script>

<style lang="less" scoped>
.my-msg {
  position: relative;
  flex-direction: row-reverse;
  img {
    margin-left: 5px;
  }
  .content {
    margin-right: 10px;
    .username {
      right: 45px;
    }
    .usercontent {
      text-align: right;
      border-radius: 18px 4px 18px 18px;
      color: #fff;
      background: #1e80ff;
    }
  }
}
.other-msg {
  img {
    margin-right: 5px;
  }
  .content {
    .username {
      left: 45px;
    }
    .usercontent {
      border-radius: 4px 18px 18px 18px;
      color: #fff;
      background: #353744;
    }
  }
}
// 公共类
.msg {
  position: relative;
  display: flex;
  min-height: 50px;
  width: 100%;
  margin: 10px 0;
  padding-top: 15px;
  :deep(.el-image) {
    > img {
      width: 100%;
      height: 100% !important;
      cursor: pointer;
      border-radius: 50%;
    }
  }
  img {
    width: 30px;
    height: 30px;
  }
  .content {
    letter-spacing: 1px;
    display: flex;
    flex-direction: column;
    margin: 0 5px;
    max-width: 80%;
    .username {
      position: absolute;
      top: 0;
      color: #7f7f7f;
      font-size: 12px;
    }
    .usercontent {
      letter-spacing: 1px;
      font-size: 16px;
      padding: 10px;
      text-align: left;
      word-break: break-all;
    }
  }
}
</style>
